"""
配置管理模块
"""
from pydantic_settings import BaseSettings
from pathlib import Path


class Settings(BaseSettings):
    """应用配置"""
    
    # 应用基本信息
    app_name: str = "人脸质量检测API"
    app_version: str = "1.0.0"
    debug: bool = False
    
    # 服务器配置
    host: str = "0.0.0.0"
    port: int = 8000
    
    # 模型配置
    model_name: str = "buffalo_l"
    model_dir: str = "./models"
    det_size: tuple = (640, 640)
    ctx_id: int = -1  # -1 表示 CPU, 0 表示 GPU 0
    
    # 人脸检测参数
    min_face_size: int = 100
    max_angle: float = 15.0
    blur_threshold: float = 60.0
    min_quality_score: float = 0.5
    
    # 文件上传配置
    max_file_size: int = 10 * 1024 * 1024  # 10MB
    allowed_extensions: list = [".jpg", ".jpeg", ".png", ".bmp"]
    upload_dir: str = "./uploads"
    
    # 日志配置
    log_level: str = "INFO"
    log_dir: str = "./logs"
    
    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"


# 创建全局配置实例
settings = Settings()

# 确保必要的目录存在
Path(settings.model_dir).mkdir(parents=True, exist_ok=True)
Path(settings.upload_dir).mkdir(parents=True, exist_ok=True)
Path(settings.log_dir).mkdir(parents=True, exist_ok=True)

